package com.dudu.dladminserver.controller;

import com.dudu.dladminserver.pojo.PageBean;
import com.dudu.dladminserver.pojo.User;
import com.dudu.dladminserver.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping
    public PageBean page(
            @RequestParam(defaultValue = "0") Integer offset,
            @RequestParam(defaultValue = "10") Integer limit,
            String username,
            String phone,
            String nickname,
            Short status
    ) {
        return userService.page(offset, limit, username, phone, nickname, status);
    }

    @DeleteMapping("/{ids}")
    public void delete(@PathVariable List<Integer> ids) {
        userService.delete(ids);
    }

    @PostMapping
    public void add(User user) {
        userService.add(user);
    }

    @PutMapping
    public void update(User user) {
        userService.update(user);
    }

    @GetMapping("/{id}")
    public User getById(@PathVariable Integer id) {
        return userService.getById(id);
    }

}
